package servlet.man;

import bean.Result;
import com.fasterxml.jackson.databind.ObjectMapper;
import dao.UserDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 李夏
 * @version 1.0
 */

//管理员修改公告
@WebServlet("/man/updateNoticeByMan")
public class UpdateNoticeByManServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        Integer noticeId = Integer.valueOf(request.getParameter("noticeId"));
        Integer buildId = null;
        if (request.getParameter("buildId") != null) {
            buildId = Integer.valueOf(request.getParameter("buildId"));
        }
        String noticeContent = null;
        if (request.getParameter("noticeContent") != null) {
            noticeContent = request.getParameter("noticeContent");
        }
       Integer data= UserDaoImpl.updateNoticeByMan(noticeId, buildId, noticeContent);
        Result result = new Result();
        if(data!=0){
            result.success(data);
            ObjectMapper objectMapper = new ObjectMapper();
            String str = objectMapper.writeValueAsString(result);
            response.setContentType("application/json;charset=utf8");
            response.getWriter().print(str);


        }else{
            result.fail();
            ObjectMapper objectMapper = new ObjectMapper();
            String str = objectMapper.writeValueAsString(result);
            response.setContentType("application/json;charset=utf8");
            response.getWriter().print(str);


        }
    }
}
